//
//  LSZAudioPlaylist.m
//  PartyClassCloud
//
//  Created by 梁素珍 on 2018/9/15.
//  Copyright © 2018年 九酷. All rights reserved.
//

#import "LSZAudioPlaylist.h"


@interface LSZAudioPlaylist ()
@property(nonatomic,strong) UITableView * tableViewList;
@property(nonatomic,strong) UIView *topView;
@property(nonatomic,strong) UIView *viewLowWhite;
@property(nonatomic,strong) NSArray * mutArrayData;

@end
@implementation LSZAudioPlaylist
-(void)initWithAudioPlaylist :(NSArray *)mutArrayData
{
    self.mutArrayData = mutArrayData;
    [self.tableViewList reloadData];
}
- (instancetype)init{
    self = [super init];
    if (self) {
        self.frame = [UIScreen mainScreen].bounds;
//        self.backgroundColor = [UIColor whiteColor];
        /*
         阴影区域点击
         */
        self.topView = [[UIView alloc]init];
        self.topView.frame = CGRectMake(0, 0, ScreenWidth, ScreenHeight);
        self.topView.backgroundColor = [UIColor clearColor];
        [self addSubview:self.topView];
        
        UITapGestureRecognizer *tapGesture = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(hiddenMBhiddenView)];
        [self.topView addGestureRecognizer:tapGesture];
        
        
        self.viewLowWhite = [[UIView alloc]init];
        self.viewLowWhite.frame = CGRectMake(0,self.topView.frame.size.height-300, ScreenWidth,300);
        self.viewLowWhite.backgroundColor = [UIColor whiteColor];
        [self.viewLowWhite.layer setMasksToBounds:YES];
        [self.viewLowWhite.layer setCornerRadius:8];
        [self addSubview:self.viewLowWhite];
        
        UILabel * labelTitle = [[UILabel alloc]init];
        labelTitle.textColor =themeColor;
        labelTitle.text = @"播放列表";
        labelTitle.font = FONT_(18);
        labelTitle.textAlignment = NSTextAlignmentCenter;
        [self.viewLowWhite addSubview:labelTitle];
        if (ScreenWidth == 320) {
            //5
            labelTitle.frame = CGRectMake(0, 0, ScreenWidth, 45);
        }else if(ScreenWidth == 375){
            // 6 7
            labelTitle.frame = CGRectMake(0, 0, ScreenWidth, 50);
        }else {
            //plus
            labelTitle.frame = CGRectMake(0, 0, ScreenWidth, 54);
        }
        UIView * viewTop = [[UIView alloc]initWithFrame:CGRectMake(0,CGRectGetMaxY(labelTitle.frame), ScreenWidth, 0.3)];
        viewTop.backgroundColor = dividerColor;
        [self.viewLowWhite addSubview:viewTop];
        
        self.tableViewList = [[UITableView alloc]initWithFrame:CGRectMake(0, CGRectGetMaxY(viewTop.frame), ScreenWidth,self.viewLowWhite.frame.size.height-CGRectGetMaxY(viewTop.frame)) style:UITableViewStyleGrouped];
        self.tableViewList.dataSource = self;
        self.tableViewList.delegate = self;
        self.tableViewList.separatorColor = dividerColor;
        self.tableViewList.backgroundColor = [UIColor whiteColor];
        self.tableViewList.separatorInset = UIEdgeInsetsMake(0, 10, 0, 10);
        [self.viewLowWhite addSubview:self.tableViewList];
        self.tableViewList.estimatedSectionFooterHeight =0;
        self.tableViewList.estimatedSectionHeaderHeight =0;
        self.tableViewList.estimatedRowHeight = 0;
        [self.tableViewList registerClass:[UITableViewCell class] forCellReuseIdentifier:@"UITableViewCell"];
    }
    return self;
}
-(CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath
{
    return 50;
}
-(CGFloat)tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)section
{
    return 0.00001;
}
-(CGFloat)tableView:(UITableView *)tableView heightForFooterInSection:(NSInteger)section
{
    return 0.00001;
}
-(NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
    return self.mutArrayData.count;
}
-(UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
    UITableViewCell * cell = [tableView dequeueReusableCellWithIdentifier:@"UITableViewCell" forIndexPath:indexPath];
    if (self.mutArrayData.count > indexPath.row) {
        LSZTertiaryInterfaceMg * mg = nil;
        mg = self.mutArrayData[indexPath.row];
        cell.textLabel.text = [NSString stringWithFormat:@"%@",mg.name];
        cell.textLabel.textColor = titleColorLSZ;
        cell.textLabel.font = FONT_(14);
    }
    cell.selectionStyle = UITableViewCellSelectionStyleNone;
    return cell;
}
-(void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
    if(self.mutArrayData.count > indexPath.row){
        NSDictionary * dic = [[NSDictionary alloc]initWithObjectsAndKeys:@(indexPath.row),@"row", nil];
        NSNotification * notificationDelete =[NSNotification notificationWithName:@"choosePlayer" object:nil userInfo:dic];
        [[NSNotificationCenter defaultCenter] postNotification:notificationDelete];
        [[NSNotificationCenter defaultCenter] removeObserver:self name:@"choosePlayer" object:nil];
        [[NSNotificationCenter defaultCenter] removeObserver:self];
        [self hiddenMBhiddenView];
    }
}
- (void)show {
    [[UIApplication sharedApplication].keyWindow addSubview:self];
}
-(void)hiddenMBhiddenView
{
    [[NSNotificationCenter defaultCenter] removeObserver:self];
    [self removeFromSuperview];
}
@end
